package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.CustomerTraceHistory;
import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.mapper.CustomerTraceHistoryMapper;
import cn.wolfcode.crm.qo.QueryObject;
import cn.wolfcode.crm.service.ICustomerTraceHistoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CustomerTraceHistoryServiceImpl implements ICustomerTraceHistoryService{
	@Autowired
	private CustomerTraceHistoryMapper customerTraceHistoryMapper;
	@Override
	public void insert(CustomerTraceHistory customerTraceHistory) {
		customerTraceHistory.setInputTime(new Date());
		customerTraceHistory.setInputUser((Employee) SecurityUtils.getSubject().getPrincipal());
		customerTraceHistoryMapper.insert(customerTraceHistory);
	}


	@Override
	public void update(CustomerTraceHistory customerTraceHistory) {
		customerTraceHistoryMapper.update(customerTraceHistory);
	}

	@Override
	public CustomerTraceHistory select(Long id) {
		CustomerTraceHistory customerTraceHistory = customerTraceHistoryMapper.select(id);
		return customerTraceHistory;
	}

	@Override
	public List<CustomerTraceHistory> list() {
		List<CustomerTraceHistory> list = customerTraceHistoryMapper.list();
		return list;
	}

	public PageInfo<CustomerTraceHistory> query(QueryObject qo) {
		PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),"cth.inputTime DESC");
        List<CustomerTraceHistory> customerTraceHistorys = customerTraceHistoryMapper.selectForList(qo);
        return new PageInfo<>(customerTraceHistorys);
	}



}
